Standard Library Modules: Fix spurious _Init_locks
dllexport
#3233
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I observed a curious message "Creating library meow.lib and object meow.exp" when consuming
import std;
with VS 2022 17.5 Preview 1. This doesn't repro when using the 17.5p1 compiler to consumeimport std;
from microsoft/STLmain
; it repros only with the shipped machinery. I haven't figured out what the difference is yet, but I did find the root cause of the message.The problem is that when we inject
stacktrace.cpp
into the import lib, it drags inyvals.h
and the headache-inducing_Init_locks
. In #3019, we guarded_Init_locks
with_CRTBLD
so it wouldn't affect users ofstl/inc
, but the problem here is thatstacktrace.cpp
is part of the STL's build, so_Init_locks
is being emitted.I have two fixes for this (either alone would be sufficient but I want to be extra sure here). First,
stacktrace.cpp
directly includesyvals.h
but barely needs it. We can replace its use of_STL_VERIFY
with direct calls tostd::abort()
, since these should only fail due to STL-internal logic errors (or something catastrophic happening at runtime).Second, let's take the additional effort to fully remove
_Init_locks
fromstl/inc
and move it into anstl/src
source-header that is then included by only the files that need_Init_locks
- never those injected into the import lib.(I experimented with a third strategy, enforcing all import lib files to be core-only via the recently-added
_ENFORCE_ONLY_CORE_HEADERS
. This is currently not possible, even after fixingstacktrace.cpp
, due tonothrow.cpp
including<new>
(which would be fairly easy to disconnect) andlocale0_implib.cpp
eventually including<xfacet>
which would be harder and scarier to rework. For the time being, I have abandoned that approach.)Note: Unlike user-visible headers, our source-headers can be very lightweight, i.e. they don't need push-pop defenses and all that. We're currently inconsistent about how to give them idempotency guards, but I went with the lightweight
#pragma once
.Here is the full repro that shows how I tracked this down to
stacktrace.cpp
:This will require MSVC-internal changes to add the new source-header.